package co.fitstart.admin.web.controller.course;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.support.Result;
import com.demo2do.core.utils.JsonUtils;
import com.demo2do.core.web.resolver.Preloading;

import co.fitstart.admin.entity.course.BatchDietProgram;
import co.fitstart.admin.service.CourseRoundService;
import co.fitstart.admin.service.GroupService;
import co.fitstart.admin.service.GroupTemplateService;
import co.fitstart.admin.web.interceptor.MenuSetting;
import co.fitstart.entity.course.round.CourseRound;
import co.fitstart.entity.courseware.dietary.Dietary;
import co.fitstart.entity.courseware.dietary.DietaryProgramTemplate;
import co.fitstart.entity.courseware.dietary.DietaryProgramType;
import co.fitstart.entity.courseware.exercise.Exercise;
import co.fitstart.entity.courseware.exercise.PlannedSchedule;
import co.fitstart.entity.courseware.fitnessgroup.BatchCourseware;
import co.fitstart.entity.courseware.fitnessgroup.BatchCoursewareType;
import co.fitstart.entity.courseware.fitnessgroup.Courseware;
import co.fitstart.entity.courseware.fitnessgroup.CoursewareMovementType;
import co.fitstart.entity.courseware.fitnessgroup.DailyCourseware;
import co.fitstart.entity.courseware.fitnessgroup.FitnessGroup;

/**
 * 每周课件
 * 
 * @author Ysy
 *
 */
@Controller
@RequestMapping("/individual-rounds/{roundId}/batch-coursewares")
@MenuSetting("menu-course")
public class IndividualBatchCoursewareController {
    
    private static final Logger logger = LoggerFactory.getLogger(IndividualBatchCoursewareController.class);
	
    @Autowired
    private GroupService groupService;
    
    @Autowired
    private GroupTemplateService groupTemplateService;
    
    @Autowired
    private CourseRoundService courseRoundService;
    
    /**
     * 
     * @param roundId
     * @param weeks
     * @param type
     * @param status
     * @return
     */
    @RequestMapping(value = "/{weeks}", method = RequestMethod.GET, params="type=weekly")
    @MenuSetting("submenu-individual-course-arrange")
    public ModelAndView index(@PathVariable("roundId") Long roundId,
                              @PathVariable("weeks") int weeks,
                              @RequestParam(name = "type") String type,
                              @RequestParam("status") String status){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/weekly-courseware-index");
        
        BatchCourseware batchCourseware = groupService.loadBatchCourseware(roundId, weeks, BatchCoursewareType.aliasOf(type));
        modelAndView.addObject("batchCourseware", batchCourseware);
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("weeks", weeks);
        modelAndView.addObject("type", type);
        modelAndView.addObject("status", status);
        
        return modelAndView;
    }
    
    @RequestMapping(value = "/{session}", method = RequestMethod.GET, params="type=course")
    @MenuSetting("submenu-individual-course-arrange")
    public ModelAndView courseIndex(@PathVariable("roundId") Long roundId,
                                    @PathVariable("session") int session){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/course-courseware-index");
        
        CourseRound courseRound = courseRoundService.loadCourseRound(roundId);
        modelAndView.addObject("courseRound", courseRound);
        
        Map<String, Object> courseCourseware = groupService.loadCourseWare(courseRound, session);
        modelAndView.addObject("courseCourseware", courseCourseware);
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("session", session);
        modelAndView.addObject("courseAmount", (courseRound.getAttrs() != null && courseRound.getAttrs().get("course_amount") != null) ? courseRound.getAttrs().get("course_amount").getValue() : courseRound.getCourse().getHours());
        
        return modelAndView;
    }
    
    /**
     * 
     * @param roundId
     * @param weeks
     * @return
     */
    @RequestMapping(value = "/weekly-plan/{weeks}", method = RequestMethod.GET)
    @MenuSetting("submenu-individual-course-arrange")
    public ModelAndView weeklyPlan(@PathVariable("roundId") Long roundId,
                                   @PathVariable("weeks") int weeks){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/weekly-plan");
        
        BatchCourseware batchCourseware = groupService.loadBatchCourseware(roundId, weeks, BatchCoursewareType.WEEKLY);
        modelAndView.addObject("batchCourseware", batchCourseware);
        
        Dietary dietary = groupService.loadDietary(batchCourseware);
        modelAndView.addObject("dietary", dietary);
        
        Exercise exercise = groupService.loadExercise(batchCourseware);
        modelAndView.addObject("exercise", exercise);
        
        List<PlannedSchedule> schedules = groupService.listPlannedSchedule(batchCourseware);
        modelAndView.addObject("schedules", schedules);
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("weeks", weeks);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param batchId
     * @param breakfast
     * @param breakfastDescription
     * @param lunch
     * @param lunchDescription
     * @param dinner
     * @param dinnerDescription
     * @param breakfastSnacks
     * @param breakfastSnacksDescription
     * @param lunchSnacks
     * @param lunchSnacksDescription
     * @param dinnerSnacks
     * @param dinnerSnacksDescription
     * @return
     */
    @RequestMapping(value = "/{batchId}", method = RequestMethod.PATCH)
    public @ResponseBody String save(@PathVariable("batchId") Long batchId,
                                     @RequestParam("breakfastDescription") String breakfastDescription,
                                     @RequestParam("lunchDescription") String lunchDescription,
                                     @RequestParam("dinnerDescription") String dinnerDescription,
                                     @RequestParam(value = "breakfastSnacksDescription", required = false) String breakfastSnacksDescription,
                                     @RequestParam(value = "lunchSnacksDescription", required = false) String lunchSnacksDescription,
                                     @RequestParam(value = "dinnerSnacksDescription", required = false) String dinnerSnacksDescription){

        Result result = new Result();

        try{

            BatchDietProgram batchDietProgram = new BatchDietProgram(breakfastDescription,
                                                                     lunchDescription,
                                                                     dinnerDescription,
                                                                     breakfastSnacksDescription,
                                                                     lunchSnacksDescription,
                                                                     dinnerSnacksDescription);
            BatchCourseware batchCourseware = groupService.loadBatchCourseware(batchId);
            
            groupService.saveDiets(batchCourseware, batchDietProgram);
            
            result.success().message("保存成功！");
        }
        catch (Exception e) {
            
            result.fail().message("保存失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param roundId
     * @param batchId
     * @return
     */
    @RequestMapping(value = "/{batchId}/link", method = RequestMethod.GET)
    public ModelAndView link(@PathVariable("roundId") Long roundId,
                             @PathVariable("batchId") Long batchId,
                             @RequestParam("type") String type,
                             @RequestParam(name = "day", required = false) Integer day){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/batch-courseware-link");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("batchId", batchId);
        modelAndView.addObject("type", type);
        modelAndView.addObject("day", day);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param roundId
     * @param batchId
     * @param type
     * @param day
     * @return
     */
    @RequestMapping(value = "/{batchId}/link", method = RequestMethod.PATCH)
    public @ResponseBody String onLink(@PathVariable("roundId") Long roundId, 
                                       @PathVariable("batchId") Long batchId,
                                       @RequestParam("type") String type,
                                       @RequestParam(name = "day", required = false) Integer day){
        
        Result result = new Result();
        
        try{
            BatchCourseware batchCourseware = groupService.loadBatchCourseware(batchId);
            
            if(StringUtils.equalsIgnoreCase(type, "weekly")) {
                groupService.linkBatchCourseware(batchCourseware);
            } else {
                DailyCourseware dailyCourseware = groupService.loadDailyCourseware(batchCourseware, day);
                groupService.linkDailyCourseware(dailyCourseware);
            }
            
            result.success().message("发送课件成功！");
        }
        catch (Exception e) {
            
            logger.error("onLink - ", e);
            result.fail().message("发送课件失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param roundId
     * @param batchId
     * @return
     */
    @RequestMapping(value = "/{batchId}/save-all", method = RequestMethod.GET)
    public ModelAndView saveAll(@PathVariable("roundId") Long roundId,
                                @PathVariable("batchId") Long batchId){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/batch-courseware-save-all");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("batchId", batchId);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param roundId
     * @param batchId
     * @return
     */
    @RequestMapping(value = "/{batchId}/save-all", method = RequestMethod.PATCH)
    public @ResponseBody String onSaveAll(@PathVariable("roundId") Long roundId, 
                                          @PathVariable("batchId") Long batchId){
        
        Result result = new Result();
        
        try{
            BatchCourseware batchCourseware = groupService.loadBatchCourseware(batchId);
            
            groupService.saveAll(batchCourseware);
            
            result.success().message("全部保存成功！");
        }
        catch (Exception e) {
            
            logger.error("onSaveAll - ", e);
            result.fail().message("全部保存失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param roundId
     * @param batchId
     * @param dietType
     * @return
     */
    @RequestMapping(value = "/{batchId}/diet", method = RequestMethod.GET)
    public ModelAndView diet(@PathVariable("roundId") Long roundId,
                             @PathVariable("batchId") Long batchId,
                             @RequestParam("dietType") String dietType) {
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/batch-courseware-diet-edit");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("batchId", batchId);
        modelAndView.addObject("dietType", dietType);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param roundId
     * @param batchId
     * @param dietaryProgramTemplateId
     * @return
     */
    @RequestMapping(value = "/{batchId}/diet", method = RequestMethod.PATCH)
    public @ResponseBody String onDiet(@PathVariable("roundId") Long roundId,
                                       @PathVariable("batchId") Long batchId,
                                       @RequestParam("dietaryProgramTemplateId") Long dietaryProgramTemplateId){
        
        Result result = new Result();
            
        try{
            
            BatchCourseware batchCourseware = groupService.loadBatchCourseware(batchId);
            DietaryProgramTemplate dietaryProgramTemplate = groupTemplateService.loadDietaryProgramTemplate(dietaryProgramTemplateId);
            
            groupService.editDiet(batchCourseware, dietaryProgramTemplate);
            
            result.success().message("修改饮食计划成功！");
            
        } catch (Exception e) {
            
            logger.error("onDiet - ", e);
            result.fail().message("修改饮食计划失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param roundId
     * @param batchId
     * @param snackType
     * @return
     */
    @RequestMapping(value = "/{batchId}/snacks", method = RequestMethod.GET)
    public ModelAndView editSnack(@PathVariable("roundId") Long roundId,
                                  @PathVariable("batchId") Long batchId,
                                  @RequestParam("snacksType") String snackType) {
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/batch-courseware-snack-edit");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("batchId", batchId);
        modelAndView.addObject("snacksType", snackType);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param roundId
     * @param batchId
     * @param snackType
     * @param dietaryProgramTemplateId
     * @return
     */
    @RequestMapping(value = "/{batchId}/snacks", method = RequestMethod.PATCH)
    public @ResponseBody String onEditSnack(@PathVariable("roundId") Long roundId,
                                              @PathVariable("batchId") Long batchId,
                                              @RequestParam("snacksType") String snackType,
                                              @RequestParam("dietaryProgramTemplateId") Long dietaryProgramTemplateId){
        
        Result result = new Result();
            
        try{
            
            BatchCourseware batchCourseware = groupService.loadBatchCourseware(batchId);
            DietaryProgramTemplate dietaryProgramTemplate = groupTemplateService.loadDietaryProgramTemplate(dietaryProgramTemplateId);
            
            groupService.editSnack(batchCourseware, dietaryProgramTemplate, DietaryProgramType.aliasOf(snackType));
            
            result.success().message("修改饮食计划成功！");
            
        } catch (Exception e) {
            
            logger.error("onEditSnack - ", e);
            result.fail().message("修改饮食计划失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param roundId
     * @param batchId
     * @return
     */
    @RequestMapping(value = "/{batchId}/edit-tags", method = RequestMethod.GET)
    public ModelAndView editTags(@PathVariable("roundId") Long roundId,
                                 @PathVariable("batchId") Long batchId) {
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/batch-courseware-edit-tag");
        
        CourseRound courseRound  = courseRoundService.loadCourseRound(roundId);
        modelAndView.addObject("student", courseRound.getStudent());
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("batchId", batchId);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param roundId
     * @param batchId
     * @param ids
     * @param names
     * @param descriptions
     * @return
     */
    @RequestMapping(value = "/{batchId}/edit-tags", method = RequestMethod.POST)
    public @ResponseBody String onEditTags(@PathVariable("roundId") Long roundId,
                                           @PathVariable("batchId") Long batchId,
                                           @RequestParam("id") List<Long> ids,
                                           @RequestParam("name") List<String> names,
                                           @RequestParam("description") List<String> descriptions) {
        
        Result result = new Result();
            
        try{
            
            groupService.editCoursewareTags(ids, names, descriptions);
            
            result.success().message("修改标签成功！");
            
        } catch (Exception e) {
            
            logger.error("onEditTags - ", e);
            result.fail().message("修改标签失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    
    /**
     * 
     * @param roundCode
     * @param roundId
     * @param weeks
     * @param dailyCoursewareId
     * @return
     */
    @RequestMapping(value = "/{weeks}/daily-coursewares/{dailyCoursewareId}/rest", method = RequestMethod.GET)
    public ModelAndView rest(@PathVariable("roundId") Long roundId, 
                             @PathVariable("weeks") int weeks,
                             @PathVariable("dailyCoursewareId") Long dailyCoursewareId){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/daily-courseware-rest");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("weeks", weeks);
        modelAndView.addObject("dailyCoursewareId", dailyCoursewareId);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param roundCode
     * @param roundId
     * @param weeks
     * @param dailyCoursewareId
     * @return
     */
    @RequestMapping(value = "/{weeks}/daily-coursewares/{dailyCoursewareId}/rest", method = RequestMethod.PATCH)
    public @ResponseBody String onRest(@PathVariable("roundId") Long roundId, 
                                       @PathVariable("weeks") int weeks,
                                       @PathVariable("dailyCoursewareId") Long dailyCoursewareId){
        
        Result result = new Result();
        
        try{
            
            DailyCourseware dailyCourseware = groupService.loadDailyCourseware(dailyCoursewareId);
            
            groupService.rest(dailyCourseware);
            
            result.success().message("设为休息日成功！");
        }
        catch (Exception e) {
            
            logger.error("onRest - ", e);
            result.fail().message("设为休息日失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param roundCode
     * @param roundId
     * @param weeks
     * @param dailyCoursewareId
     * @return
     */
    @RequestMapping(value = "/{weeks}/daily-coursewares/{dailyCoursewareId}/coursewares/create", method = RequestMethod.GET)
    public ModelAndView create(@PathVariable("roundId") Long roundId, 
                               @PathVariable("weeks") int weeks,
                               @PathVariable("dailyCoursewareId")int dailyCoursewareId,
                               @RequestParam("coursewareType") String coursewareType,
                               @RequestParam(value = "type", required = false) String type){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/courseware-create");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("weeks", weeks);
        modelAndView.addObject("dailyCoursewareId", dailyCoursewareId);
        modelAndView.addObject("coursewareType", coursewareType);
        modelAndView.addObject("type", type);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param roundCode
     * @param roundId
     * @param weeks
     * @param dailyCoursewareId
     * @param courseware
     * @return
     */
    @RequestMapping(value = "/{weeks}/daily-coursewares/{dailyCoursewareId}/coursewares", method = RequestMethod.POST)
    public @ResponseBody String onCreate(@PathVariable("roundId") Long roundId, 
                                         @PathVariable("weeks") int weeks,
                                         @PathVariable("dailyCoursewareId") Long dailyCoursewareId,
                                         @RequestParam(name = "movementType", required = false) String type,
                                         Courseware courseware){
        
        Result result = new Result();
        
        try{
            
            DailyCourseware dailyCourseware = groupService.loadDailyCourseware(dailyCoursewareId);
            
            groupService.createCourseware(dailyCourseware, courseware, CoursewareMovementType.aliasOf(type));
            
            result.success().message("添加动作成功！");
        } catch (Exception e) {
            
            logger.error("onCreate - ", e);
            result.fail().message("添加动作失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param roundId
     * @param weeks
     * @param dailyCoursewareId
     * @param type
     * @return
     */
    @RequestMapping(value = "/{weeks}/daily-coursewares/{dailyCoursewareId}/coursewares/action-group", method = RequestMethod.GET)
    public ModelAndView actionGroup(@PathVariable("roundId") Long roundId, 
                                    @PathVariable("weeks") int weeks,
                                    @PathVariable("dailyCoursewareId")int dailyCoursewareId,
                                    @RequestParam("coursewareType") String coursewareType,
                                    @RequestParam(value = "type", required = false) String type){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/courseware-action-group");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("weeks", weeks);
        modelAndView.addObject("dailyCoursewareId", dailyCoursewareId);
        modelAndView.addObject("coursewareType", coursewareType);
        modelAndView.addObject("type", type);
        
        return modelAndView;
    }
    
    /**
     * 
     * @param roundId
     * @param weeks
     * @param dailyCoursewareId
     * @param type
     * @param groupId
     * @return
     */
    @RequestMapping(value = "/{weeks}/daily-coursewares/{dailyCoursewareId}/coursewares/action-group", method = RequestMethod.POST)
    public @ResponseBody String onActionGroup(@PathVariable("roundId") Long roundId, 
                                              @PathVariable("weeks") int weeks,
                                              @PathVariable("dailyCoursewareId") Long dailyCoursewareId,
                                              @RequestParam(name = "movementType", required = false) String type,
                                              @RequestParam("groupId") Long groupId){
        
        Result result = new Result();
        
        try{
            
            DailyCourseware dailyCourseware = groupService.loadDailyCourseware(dailyCoursewareId);
            FitnessGroup fitnessGroup = groupTemplateService.loadFitnessGroup(groupId);
            
            groupService.createCoursewareGroup(dailyCourseware, fitnessGroup, CoursewareMovementType.aliasOf(type));
            
            result.success().message("添加动作组成功！");
        } catch (Exception e) {
            
            logger.error("onActionGroup - ", e);
            result.fail().message("添加动作组失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    /**
     * 
     * @param roundCode
     * @param roundId
     * @param weeks
     * @param dailyCoursewareId
     * @param coursewareId
     * @return
     */
    @RequestMapping(value = "/{weeks}/daily-coursewares/{dailyCoursewareId}/coursewares/{coursewareId}/edit", method = RequestMethod.GET)
    public ModelAndView edit(@PathVariable("roundId") Long roundId,
                             @PathVariable("weeks") int weeks,
                             @PathVariable("dailyCoursewareId") Long dailyCoursewareId,
                             @PathVariable("coursewareId") Long coursewareId){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/courseware-edit");
        
        Courseware courseware = groupService.loadCourseware(coursewareId);
        modelAndView.addObject("courseware", courseware);
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("weeks", weeks);
        modelAndView.addObject("dailyCoursewareId", dailyCoursewareId);
        
        return modelAndView;
    }
    
    /**
     * edit the daily movement
     * 
     * @param roundId
     * @param movementId
     * @param weeks
     * @param days
     * @return
     */
    @RequestMapping(value = "/{weeks}/daily-coursewares/{dailyCoursewareId}/coursewares/{coursewareId}", method = RequestMethod.PATCH)
    public @ResponseBody String onEdit(@PathVariable("roundId") Long roundId,
                                       @PathVariable("weeks") int weeks,
                                       @PathVariable("dailyCoursewareId") Long dailyCoursewareId,
                                       @Preloading("coursewareId") Courseware courseware){
        
        Result result = new Result();
        
        try{
            
            groupService.editCourseware(courseware);
            
            result.success().message("修改动作成功！");
        } catch (Exception e) {
            
            logger.error("onEdit - ", e);
            result.fail().message("修改动作失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
    
    /**
     * Display delete the daily movement panel
     * 
     * @param roundId
     * @param movementId
     * @param weeks
     * @param days
     * @return
     */
    @RequestMapping(value = "/{weeks}/daily-coursewares/{dailyCoursewareId}/coursewares/{coursewareId}/delete", method = RequestMethod.GET)
    public ModelAndView delete(@PathVariable("roundId") Long roundId,
                               @PathVariable("weeks") int weeks,
                               @PathVariable("dailyCoursewareId") Long dailyCoursewareId,
                               @PathVariable("coursewareId") Long coursewareId){
        
        ModelAndView modelAndView = new ModelAndView("course/individual/batch-courseware/courseware-delete");
        
        modelAndView.addObject("roundId", roundId);
        modelAndView.addObject("weeks", weeks);
        modelAndView.addObject("dailyCoursewareId", dailyCoursewareId);
        modelAndView.addObject("coursewareId", coursewareId);
        
        return modelAndView;
    }
    
    

    /**
     * delete the daily movement
     * 
     * @param roundId
     * @param movementId
     * @param weeks
     * @param days
     * @return
     */
    @RequestMapping(value = "/{weeks}/daily-coursewares/{dailyCoursewareId}/coursewares/{coursewareId}", method = RequestMethod.DELETE)
    public @ResponseBody String onDelete(@PathVariable("roundId") Long roundId,
                                         @PathVariable("weeks") int weeks,
                                         @PathVariable("dailyCoursewareId") Long dailyCoursewareId,
                                         @Preloading("coursewareId") Courseware courseware){
        
        Result result = new Result();
        
        try{
            
            groupService.deleteCourseware(courseware);
            
            result.success().message("删除动作成功！");
        }
        catch (Exception e) {
            
            logger.error("onDelete - ", e);
            result.fail().message("删除动作失败！");
        } 
        
        return JsonUtils.toJsonString(result);
    }
    
}
